package com.myproject.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    private static final Logger logger = LoggerFactory.getLogger(HelloController.class);


    @GetMapping("/hello")
    public String method(String string){

        logger.info("controller method");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "hello";
    }

    //无返回值
    @GetMapping("/method1")
    public void method1(String string){

        System.out.println("method1");;

    }

    //controller中启动其他线程
    @GetMapping("/method2")
    public String method2(String string){

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int count = 0;
                while (true){
                    count++;
                    /*try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }*/
                    System.out.println(Thread.currentThread().getName()+" hello "+count);
                    if (count==100){
                        break;
                    }
                }
            }
        });
        thread.start();
        System.out.println("method2");

        return "method2..";
    }




}
